package com.bangdream.michelia.utils;

import android.widget.EditText;
import android.widget.TextView;

/**
 * Created by Mr.Wang on 2017/9/8.
 * 909732184@qq.com
 */

public class TextViewUtil {
    public static final String TAG = "TextViewUtil";
    public static final int maxDescripLine = 3;                                                             //EditText默认最大展示行数
    public static void OpenText(final boolean isOpen, final EditText textView)
    {
        textView.post(new Runnable() {
            @Override
            public void run() {
                MyLog.d(TAG,"文本行数为"+textView.getLineCount());
                //如果展开则设置高度为文本行数*文本行高 收缩则设置高度为文本默认行数*行高
                if(isOpen)
                {
                    textView.setHeight(textView.getLineCount()*textView.getLineHeight());
                }
                else {
                    textView.setHeight(maxDescripLine*textView.getLineHeight());
                }
            }
        });
    }

    public static void setTextEmpty(TextView textView,String text)
    {
        setTextEmpty(textView,text,null);
    }

    public static void setTextEmpty(TextView textView,String text,String stDefault)
    {
        if(stDefault==null){
            stDefault = "";
        }
        String stText = text==null?stDefault:text;
        textView.setText(stText);
    }

}
